home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / reveal12.arc / REVEAL.DOC < prev    next >
Text File  |  1991-05-06  |  7KB  |  172 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.                              REVEAL!
  7.  
  8.                          A Learning Tool
  9.  
  10. EbSoft
  11. 8 Darnock Court,
  12. Brampton, Ontario,
  13. L6Z 2X3
  14. CANADA
  15.  
  16. Please see the README.DOC file for information on how to register 
  17. this shareware program and how to receive the source code so you 
  18. can see how this program works.
  19.  
  20. REVEAL!
  21.  
  22. Given a little knowledge and the right tools, you can persuade DOS 
  23. to reveal its innermost secrets.  With REVEAL as your guide, you 
  24. will be able to understand exactly how it is that DOS allows 
  25. programs and data to coexist in its memory workspace, in what 
  26. order they are loaded, and how they interact. You can then use 
  27. this information to squeeze every last drop of RAM power from your 
  28. machine!
  29.  
  30. USING THE PROGRAM:
  31.  
  32. When you run the program, by entering REVEAL <Enter> at the DOS 
  33. prompt, you will be presented with the main screen.  At the left, 
  34. a flashing message informs you that the program is scanning the 
  35. DOS memory workspace for memory control blocks.  When this is 
  36. done, the total number of blocks found is displayed at the top 
  37. left, with a summary of the first 20 blocks below.  The highlight 
  38. bar is over the first block.  The right side of the screen 
  39. contains detailed information about the highlighted block.
  40.  
  41. You may select a memory block for analysis by using the cursor 
  42. movement keys.  The up and down keys move the highlight bar by 
  43. one, while the PgUp and PgDn keys move in steps of 20.  The Home 
  44. and End keys take you to the first and last blocks respectively.
  45. The <Esc> key will return you to DOS, and <F1> will bring up a 
  46. help screen.
  47.  
  48. The Summary line for each block contains the following data:
  49. #        - The block number
  50. Seg      - The segment where the memory block's Memory Control 
  51.            Block header is found.  The actual memory block starts 
  52.            at the next segment
  53. Use      - What DOS uses this block for - values are: 
  54.            Data, Program, Environment, Batch, Unallocated
  55. Filespec - The filename associated with this block
  56. Len      - The hex length of the block in paragraphs of 16 bytes
  57.  
  58. The Analysis Box on the right contains this information and more 
  59. details, such as the full filespec associated with the current 
  60. block and the parameters entered on the command line when the 
  61. program was invoked.
  62.  
  63. If you want to inspect the actual memory occupied by the current 
  64. block, press <Enter>.  You will be presented with the Inspect 
  65. screen.  The first 20 paragraphs of memory are displayed in both 
  66. hexadecimal and ASCII format, starting with the MCB header.  You 
  67. can move through the memory segment 16 paragraphs at a time with 
  68. the PgUp or PgDn keys, or go to the start and end of the current 
  69. memory segment with the Home and End keys.
  70.  
  71. To specify a new address to inspect, press "A".  You will be asked 
  72. to enter a segmented address in hexadecimal.
  73.  
  74. The <ESC> key will return you to the main screen.
  75.  
  76. HOW THE PROGRAM WORKS:
  77.  
  78. Reveal analyzes your PC's memory by tracing DOS' linked chain of 
  79. Memory Control Blocks (MCBs) and looking for known characteristics 
  80. to determine how DOS is using the various blocks of memory.
  81.  
  82. An MCB is a 16-byte structure marking the beginning of an 
  83. allocated block of memory.  MCBs are always paragraph-aligned, 
  84. which means they begin at an offset divisible by 16.  The layout 
  85. of these structures is as follows:
  86.  
  87. Offset:      Contents:
  88.  
  89. 0 (1 byte)   "M" or "Z".  "Z" means this is the last MCB.
  90.              (Mark Zbikowski was one of the DOS developers.)
  91. 1 (2 bytes)  Owner - The segment of the Program Segment Prefix for 
  92.              the program that owns this memory block.  If this is
  93.              0000, the block is unallocated.
  94. 3 (2 bytes)  Length of the memory block in 16-byte paragraphs. 
  95. 4 (11 bytes) This area is not used until DOS 4.0, where a 
  96.              filename can be found here.  REVEAL uses other 
  97.              methods to find this information and so remains 
  98.              compatible for DOS 3.X users.
  99.  
  100. Since each MCB contains the block length, the next MCB can be 
  101. found by calculating its segment from the present MCB segment and 
  102. the block length.  This makes the MCBs link to each other in a 
  103. chain.  There is a DOS function (undocumented by Microsoft) which 
  104. will return a pointer to a table of DOS system information which 
  105. contains the address of the first MCB in the chain.  If you call 
  106. INT 21H, service 52H, the segment of the first MCB will be found 
  107. at the location pointed to by ES:[BX-2].
  108.  
  109. There are 5 distinct types of memory blocks in a DOS system. They 
  110. are as follows:
  111.  
  112. Unallocated - The block is not in use and is available to be 
  113.               allocated.
  114.  
  115. Environment - A copy of the DOS environment strings is loaded into 
  116.               memory with each program.
  117.  
  118. Program     - DOS loads the program into memory, preceded by a 
  119.               Program Segment Prefix (PSP) of 256 bytes, which
  120.               contains system information and default data areas.
  121.  
  122. Batch       - While a batch file is executing, DOS keeps 
  123.               information including its disk location in memory.
  124.  
  125. Data        - An allocated block that isn't used for the purposes 
  126.               listed above.
  127.  
  128. With examination, each block's type can be determined.  The 
  129. following methods are used by REVEAL to determine block usage:
  130.  
  131. - An Unallocated block will have 0000 as its owner's segment 
  132.   address.
  133. - Each program has its own Environment block, pointed to by a word 
  134.   at offset 2Ch of the program's PSP.  If a block's owner's PSP 
  135.   environment pointer points back to that block, it is an 
  136.   Environment block.
  137. - A Program Block will always start with the two bytes CD 20 or
  138.   CD 27 - the first two bytes of the PSP.
  139. - The full path specification of the batch file is found at offset 
  140.   2Fh from the start of the block.  This means that the characters 
  141.   ":\" will always be found at offset 30h.
  142. - Otherwise, it's a data block.
  143.  
  144. Sometimes, the tests REVEAL uses can fail to properly identify 
  145. some memory blocks, but the vast majority of cases will be covered 
  146. by these rules.  Manual inspection of the memory locations with 
  147. REVEAL's Inspect feature will allow you to make the final decision.
  148.  
  149. You can also find the full pathname of each program and the 
  150. parameters entered at the DOS command line when it was invoked 
  151. (the command tail).  The pathname of the program is stored at the 
  152. end of the DOS environment block, after the environment strings.
  153. The command tail is found at offset 81 within the program's PSP, 
  154. with its length specified at offset 80.  This space is also used, 
  155. however, as the default Disk Transfer Area for the program, and 
  156. unless the program defines its own DTA (which most do), the 
  157. command tail could be overwritten.
  158.  
  159. Batch blocks contain information about a BAT file which has not 
  160. yet finished executing.  At offset 07h of the block, a 2-byte 
  161. pointer is found that specifies the byte location of the next 
  162. command to be executed in the batch file.  After the full pathname 
  163. of the file, delimited by a 00h byte and found at offset 30h in 
  164. the block, the list of command line parameters is kept, starting 
  165. with %0.  Parameters are separated by 0Dh and the list ends with a 
  166. 00h byte. 
  167.  
  168. For exact implementation of these principles, order the source 
  169. code for REVEAL - see README.DOC for instructions.
  170.  
  171.  
  172.